home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
SCLIB.ARJ
/
SCL1SAMP.EXE
/
RECORDF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-01
|
2KB
|
104 lines
#include <scl1.h>
/* This file shows the use of the RecordFile function to create and
and use a data file organized in records */
char buffer[4]; /* data buffer */
/* this data will be stored in RecordFile file */
char *test[]={"1","2","3","4","5","6","7"};
/* RecordFile struct */
RFData rfd={"TEST.RF",buffer,2,};
main()
{
int Mess,i;
if(Mess=RecordFile(RF_CREATE,&rfd)) /* create file */
{
printf("%i\n",Mess); /* error */
exit(-1);
}
for(i=0;i < 7;++i) /* add records */
{
rfd.Buffer=test[i];
if(Mess=RecordFile(RF_ADD,&rfd))
{
printf("%i\n",Mess); /* error */
RecordFile(RF_CLOSE,&rfd);
exit(-1);
}
/* read and print file position and size */
printf("Adding record %i, file position: %li, file size: %li\n",i,rfd.FPos,rfd.FSize);
}
printf("Press any key...\n");
GetKey();
/* make rfd.Buffer point to our buffer so that all data is be copied
to our buffer. We'll read all records */
printf("Records in the order the were saved\n");
rfd.Buffer=buffer;
if(RecordFile(RF_FIRST,&rfd)==RF_OK) /* get first record */
{
do /* print it */
{
printf("%s\n",buffer);
}while(RecordFile(RF_NEXT,&rfd) != RF_EOF); /* get next */
}
printf("Press any key...\n");
GetKey();
printf("Records in reverse order\n");
/* get last record */
if(RecordFile(RF_LAST,&rfd)==RF_OK)
{
do
{
printf("%s\n",buffer);
}while(RecordFile(RF_PREVIOUS,&rfd) != RF_BOF); /* previous */
}
printf("Press any key...\n");
GetKey();
printf("Record=3 modified to A\n");
/* look for record with data 3 and modify it */
if(RecordFile(RF_FIRST,&rfd)==RF_OK) /* get first */
{
do
{
if(strcmp(buffer,"3")==0) /* equal? */
{
strcpy(buffer,"A"); /* modify */
RecordFile(RF_WRITE,&rfd); /* write data */
}
}while(RecordFile(RF_NEXT,&rfd) != RF_EOF); /* get next */
}
/* show all records */
if(RecordFile(RF_FIRST,&rfd)==RF_OK)
{
do
{
printf("%s\n",buffer);
}while(RecordFile(RF_NEXT,&rfd) != RF_EOF);
}
RecordFile(RF_CLOSE,&rfd); /* close file */
GetKey();
}